package com.juyu.miliao.api.controller.active.gift;

import com.alibaba.fastjson.JSONObject;
import com.juyu.miliao.api.service.ActiveGiftService;
import com.juyu.miliao.api.service.OpenApiService;
import com.juyu.miliao.common.domain.CommonHead;
import com.juyu.miliao.common.domain.OpenApiStatus;
import com.juyu.miliao.common.domain.Subject;
import com.juyu.miliao.common.util.VerifyUtil;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 活动
 * 礼物争夺战
 * by wbf 2019/09/17
 */
@RestController
@RequestMapping("/active/gift")
public class ActiveGiftController {
    @Resource
    private ActiveGiftService activeGiftService;
    @Resource
    private OpenApiService openApiService;

    /**
     * 获取活动信息：开关
     * JSONObject
     * homeIcon 首页主播活动图标
     * isShowHome 1显示 2否
     * chatIcon 聊天窗主播活动图标
     * isShowChat 1显示 2否
     * @return
     */
    @GetMapping("/switch/info")
    public JSONObject getActiveGiftSwitchInfo(HttpServletRequest request){
        CommonHead com = VerifyUtil.verifyCommonHead(request);
        OpenApiStatus ops = openApiService.getOpenApi(com);
        if (ops != null && ops.getForwardAudit() && ops.getBackAudit()) {
            return new JSONObject();
        }
        return activeGiftService.getActiveGiftSwitchInfo();
    }

    /**
     * 获取活动信息：h5页面基本信息
     * type:1今日榜,2昨日榜
     * JSONObject
     * icon 礼物图片
     * isActive 0未开始 1进行中 2已结束
     * activeTime 剩余时间
     * giftNum 获取奖励最低礼物数
     * @return
     */
    @GetMapping("/info/{type}")
    public JSONObject getActiveGiftInfo(@PathVariable("type") Integer type){
        return activeGiftService.getActiveGiftInfo(type);
    }

    /**
     * 获取礼物风云榜
     * type:1今日榜,2昨日榜
     * @return
     */
    @GetMapping("/list/{type}")
    public JSONObject getActiveGiftList(Authentication token,@PathVariable("type") Integer type){
        Subject subject = (Subject) token.getPrincipal();
        return activeGiftService.getActiveGiftList(subject.getId(),type);
    }

}
